﻿/*
 * Created by SharpDevelop.
 * User: pc
 * Date: 03/11/2011
 * Time: 08:18 a.m.
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using Business_Entity;

namespace DAOFactory
{
	/// <summary>
	/// Description of DAOCategoriaCliente.
	/// </summary>
	public class DAOCategoriaCliente
	{
		public DAOCategoriaCliente()
		{		
			
			
		}
		
		public List<BECategoriaCliente> obtenerCategoriaCliente()
		{
			SqlDataReader amd = null;
			List<BECategoriaCliente> lista = new List<BECategoriaCliente>();
			
			try{
				SqlCommand cmd = new SqlCommand("VENTAS_OBTENER_CATEGORIA_CLIENTE_R", ConnectionManager.getConnection());
				cmd.CommandType = CommandType.StoredProcedure;
					
				amd = cmd.ExecuteReader();				
				
				if (amd.HasRows) 
				{
					lista.Add(new BECategoriaCliente(-1,"<Seleccionar>"));
					
					while(amd.Read())
					{
						BECategoriaCliente categoriaCliente = new BECategoriaCliente();						
						categoriaCliente.IdCategoria = Int32.Parse(amd[0].ToString());
						categoriaCliente.Nombre = amd[1].ToString();
						lista.Add(categoriaCliente);

					}
				}
			}
			catch(SqlException e){
				System.Windows.Forms.MessageBox.Show(e.ToString(),"Error");				
			}
			
			if(amd != null)
				amd.Close();
			return lista;				
		}
	}
}
